{extend name='public/layout' /}
{block name='head'}
<link rel="stylesheet" href="/css/admin/login.css"/>
{/block}

{block name="header"}
{/block}

{block name="aside"}
{/block}

{block name='body-wrapper'}
<div class="layadmin-user-login">

	<div class="layadmin-user-login-main">
		<div class="layadmin-user-login-box layadmin-user-login-header">
			<h2>总后台</h2>
			<p>快速搭建属于自己的博客网站</p>
		</div>
		<form class="layadmin-user-login-box layadmin-user-login-body layui-form" action="{:url()}" method="post">

			<div class="layui-form-item">
				<label class="layadmin-user-login-icon layui-icon layui-icon-username" for="username"></label>
				<input type="text" name="user" id="username" lay-verify="required|user" placeholder="用户名" class="layui-input">
			</div>

			<div class="layui-form-item">
				<label class="layadmin-user-login-icon layui-icon layui-icon-password" for="password"></label>
				<input type="password" name="pwd" id="password" lay-verify="required|pwd" placeholder="密码" class="layui-input">
			</div>

			<div class="layui-form-item">
				<div class="layui-row">
					<div class="layui-col-xs7">
						<label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="verify"></label>
						<input type="text" name="verify" id="verify" lay-verify="required" placeholder="图形验证码" class="layui-input">
					</div>
					<div class="layui-col-xs5">
						<div style="margin-left: 10px;">
							<img src="" class="layadmin-user-login-codeimg" id="verify-code">
						</div>
					</div>
				</div>
			</div>

			<div class="layui-form-item">
				<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login">登 入</button>
			</div>

		</form>
	</div>

</div>
{/block}

{block name="foot"}
<script type="text/javascript">
layui.form.verify({
	user: function(value, item) { //value：表单的值、item：表单的DOM对象
		if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
			return '用户名不能有特殊字符';
		}
		if (/(^_)|(__)|(_+$)/.test(value)) {
			return '用户名首尾不能出现下划线\'_\'';
		}
		if (/^\d+\d+\d$/.test(value)) {
			return '用户名不能全为数字';
		}
	},
	//我们既支持上述函数式的方式，也支持下述数组的形式
	//数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
	pass: [
		/^[\S]{6,16}$/,
		'密码必须6到16位，且不能出现空格'
	]
});

layui.form.on('submit(login)', function(data) {
	try {
		xin.request.post("{:url()}", data.field).then(function(res) {
			setTimeout(function() {
				location.href = res.url;
			}, 1000);
		}, function(res) {
			$('[name="verify"]').val('');
			$('#verify-code').click();
		});
	} catch (e) {
		console.error(e);
	}
	//阻止表单跳转。如果需要表单跳转，去掉这段即可。
	return false;
});

$(function() {
	//刷新验证码
	var verifyUrl = '{:captcha_src("admin")}';
	$('#verify-code').on('click', function() {
		$(this).attr('src', verifyUrl + "?_r=" + new Date().getTime());
	}).click();
});
</script>
{/block}

